#version 300 es

#ifdef GL_ES
precision mediump float;
#endif

#define TWO_PI 6.28318530718

uniform vec2 u_resolution;
uniform float u_time;

vec2 rect(vec2 st, vec2 pos, vec2 size, float edge) {
  vec2 p = st - pos - (size * 0.5);
  p = abs(p);

  vec2 bl1 = step(size * 0.5, p);
  vec2 bl = 1.0 - bl1;

  vec2 e = 1.0 - step(size * 0.5 + vec2(edge), p);

  return vec2(bl.x * bl.y, min(1.0, (bl1.x + bl1.y)) * e.x * e.y);
}

out vec4 outColor;

void main() {

  float solution = min(u_resolution.x, u_resolution.y);
  vec2 st = (gl_FragCoord.xy - u_resolution / 2.0) / solution;
  vec2 s = vec2(1.0, 1.0) - step(0.5, abs(st));
  if(s.x * s.y < 0.00001) {
    discard;
  }

  vec3 color = vec3(0.1);

  vec2 pct = rect(st, vec2(-0.05, -0.1), vec2(0.3, 0.35), 0.01);
  color = mix(color, vec3(1.0, 0.0, 0.0), pct.x); // area
  color = mix(color, vec3(0.0, 1.0, 0.0), pct.y); // edge

  pct = rect(st, vec2(-0.35, -0.4), vec2(0.2, 0.35), 0.01);
  color = mix(color, vec3(0.098, 0.0, 1.0), pct.x); // area
  color = mix(color, vec3(1.0, 0.0, 1.0), pct.y); // edge

  outColor = vec4(color, 1.0);
}
